/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AñadirResiduos.java
 *
 * Created on 13-feb-2012, 17:55:57
 */

package interfazgrafica.modificar.residuosmedicos;

import interfazgrafica.ayuda.VentanaAyuda;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Lauaa
 */
public class AñadirResiduos extends javax.swing.JFrame {
    private final Connection conn;
    private final Statement stmt;
    private String[] args;

    /** Creates new form AñadirResiduos */
    public AñadirResiduos(java.awt.Frame parent, boolean modal) throws ClassNotFoundException, SQLException {
        initComponents();
        //Accedo a la base de datos.
            Class.forName("oracle.jdbc.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "system", "terrano89");
            stmt = conn.createStatement();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabelNumeroAnimales = new javax.swing.JLabel();
        jLabelId = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabeFEcha = new javax.swing.JLabel();
        jTextFieldId = new javax.swing.JTextField();
        jTextFieldGestor = new javax.swing.JTextField();
        jTextFieldFecha = new javax.swing.JTextField();
        jTextFieldObservaciones = new javax.swing.JTextField();
        jLabelDescripcion = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cowmanager.CowManagerApp.class).getContext().getResourceMap(AñadirResiduos.class);
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabelNumeroAnimales.setText(resourceMap.getString("jLabelNumeroAnimales.text")); // NOI18N
        jLabelNumeroAnimales.setName("jLabelNumeroAnimales"); // NOI18N

        jLabelId.setText(resourceMap.getString("jLabelId.text")); // NOI18N
        jLabelId.setName("jLabelId"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabeFEcha.setText(resourceMap.getString("jLabeFEcha.text")); // NOI18N
        jLabeFEcha.setName("jLabeFEcha"); // NOI18N

        jTextFieldId.setName("jTextFieldId"); // NOI18N
        jTextFieldId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdActionPerformed(evt);
            }
        });

        jTextFieldGestor.setName("jTextFieldGestor"); // NOI18N

        jTextFieldFecha.setName("jTextFieldFecha"); // NOI18N

        jTextFieldObservaciones.setName("jTextFieldObservaciones"); // NOI18N

        jLabelDescripcion.setText(resourceMap.getString("jLabelDescripcion.text")); // NOI18N
        jLabelDescripcion.setName("jLabelDescripcion"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(337, Short.MAX_VALUE)
                        .addComponent(jButton3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelNumeroAnimales, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabelDescripcion)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGap(29, 29, 29)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabeFEcha)
                                        .addComponent(jLabelId)))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldObservaciones)
                            .addComponent(jTextFieldGestor, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextFieldId)
                            .addComponent(jTextFieldFecha, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabeFEcha)
                            .addComponent(jTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelId)
                            .addComponent(jTextFieldId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelDescripcion)
                            .addComponent(jTextFieldGestor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelNumeroAnimales)
                            .addComponent(jTextFieldObservaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jButton1)
                        .addGap(46, 46, 46)
                        .addComponent(jButton2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String consulta = "INSERT INTO Incidencias VALUES (";
        consulta = consulta + "'" + jTextFieldId.getText() +"', ";
        consulta = consulta + "'" + jTextFieldFecha.getText() +"', ";
        consulta = consulta + "'" + jTextFieldGestor.getText() +"', ";
        consulta = consulta + "'" + jTextFieldObservaciones.getText() +"')";

        //Hago una consulta y la guardo en rs.
        ResultSet rs = null;
        try {
            rs = stmt.executeQuery(consulta);
        } catch (SQLException ex) {
            Logger.getLogger(AñadirResiduos.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            rs.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirResiduos.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            stmt.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirResiduos.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(AñadirResiduos.class.getName()).log(Level.SEVERE, null, ex);
        }
        ModificarResiduosMedicos.main(args);
        this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jTextFieldIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTextFieldIdActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        VentanaAyuda ayuda = new VentanaAyuda("Modiificar residuos medicos");
        ayuda.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(final String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    AñadirResiduos dialog = new AñadirResiduos(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        public void windowClosing(java.awt.event.WindowEvent e) {
                            ModificarResiduosMedicos.main(args);
                        }
                    });
                    dialog.setVisible(true);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(AñadirResiduos.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(AñadirResiduos.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabeFEcha;
    private javax.swing.JLabel jLabelDescripcion;
    private javax.swing.JLabel jLabelId;
    private javax.swing.JLabel jLabelNumeroAnimales;
    private javax.swing.JTextField jTextFieldFecha;
    private javax.swing.JTextField jTextFieldGestor;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldObservaciones;
    // End of variables declaration//GEN-END:variables

}
